<?php
declare(strict_types=1);

namespace App\Wxc\Controller\SharerMp\V1;

use App\Wxc\Request\SharerMp\V1\LoginRequest;
use App\Wxc\Service\Input\SharerMpLoginInput;
use App\Wxc\Service\WxcSharerMpService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\PostMapping;
use Mine\Middlewares\CheckModuleMiddleware;
use Mine\MineController;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * 登录接口
 */
#[Controller(prefix: "wxc/sharer-mp/v1/auth")]
#[Middleware(middleware: CheckModuleMiddleware::class)]
class LoginController extends MineController
{
    #[Inject]
    protected WxcSharerMpService $mpService;

    /**
     * 登录
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('login')]
    public function login(): ResponseInterface
    {
        $req = LoginRequest::validateAndCreate($this->request->all());
        return $this->success('ok', $this->mpService->login(SharerMpLoginInput::from($req)));
    }
}
